

<link rel="stylesheet" href="/Static/mobile/vant/index.css">
<script src="/Static/mobile/vant/vue.min.js"></script>
<script src="/Static/mobile/vant/vant.min.js"></script>
<link rel="stylesheet" href="/Static/mobile/applogin/css/mylogin.css">
<div  style="display:none;" id="app" class='conatainer'>
    <div class="btn-group">
        <div v-if="haswx" @click="login" class='wx-login-div'>
            <img class='icon_pic wx-icon' src="/Static/mobile/applogin/images/wx.png" alt="">
            <span>微信登陆</span>
        </div>

        <div @click="location.href='/mobile/login/mobilelogin'" class='mobile-login-div'>
            <img class='icon_pic' src="/Static/mobile/applogin/images/mobile_white.png" alt="">
            <span>手机登陆</span>
        </div>
    </div>
</div>

<script>
    function vueInit () {
        var app = new Vue({
            el: '#app',
            data: {
                mobileLoginShow: false,
                loginInfo:{},
                register:{},
                haswx: false,
                activeTab:0,
                sendNum:0,
                sendText:'发送验证码',
                version:'',
                os:''
            },
            watch: {
                sendNum: function (val,oldval) {
                    if(val!=0) {
                        this.sendText = '已发送';
                    }else{
                        this.sendText = '发送验证码';
                        clearInterval(window.sendTask);
                    }
                }
            },
            created:function () {
                var self = this;
            },
            mounted: function () {
                this.version = plus.runtime.version;
                this.os = plus.os.name;
                /* var quit = '<?=get("quit")?>';
                plus.storage.removeItem('token');
                if(quit) {
                    window.location.href = '/mobile/index';
                    return;
                } */
                $('#app').show();
                
                var self = this;
                if(plus.runtime.isApplicationExist({pname:'com.tencent.mm',action:'weixin://'})){
                    self.haswx = true;
                    if(self.haswx) {
                        var token = plus.storage.getItem('token');
                        if(token) {
                            //window.location.replace('/mobile/index?token='+token);
                        }
                    }
                }
                
            },
            methods: {
                login: function () {
                    var self = this
                    if(!window.plus) {
                        return false
                    }
                    //return false; 
                    plus.oauth.getServices( function (auths) {
                        var wxauth;
                        for(var i=0;i<auths.length;i++) {
                            if(auths[i].id=='weixin') {
                                wxauth = auths[i];
                                break;
                            }
                        }


                        wxauth.authorize(function(e){
                            //alert("授权ok："+e.code);
                            $.ajax({
                                type: 'post',
                                data: {
                                    code:e.code
                                },
                                url: '/mobile/login/app'
                            }).then(function(res) {
                                if(res.ret==0) {
                                    plus.storage.setItem('token', getCookie('token'));
                                    window.location.replace('/mobile/index');
                                }else{
                                    showerror(res.msg);
                                }
                            })
                        }, function(e){
                            alert("授权失败："+JSON.stringify(e));
                        }, {scope:'snsapi_userinfo',state:'authorizetest',appid:'wxb95a3deeed5f0cb0'});
                       
                    })
                }
            }
        });
    }
    document.addEventListener("plusready",function(){
        vueInit();
    },false);
    
    
</script>
<style>
    .van-cell__title {
        max-width: 90px;
    }

    .van-cell__value {
        text-align: left;
    }
</style>